/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Visual.java
 *
 * Created on 25/01/2013, 03:02:49
 */
package gui;

import java.awt.Color;
import java.awt.Dimension;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import utilities.IOFile;
import visual.ontogrator.pkg2.Gene;
import visual.ontogrator.pkg2.Gene;
import visual.ontogrator.pkg2.LoadSave;
import visual.ontogrator.pkg2.Network;
import visual.ontogrator.pkg2.Network;
import visual.ontogrator.pkg2.SearchEngine;
import visual.ontogrator.pkg2.SearchEngine;
import visual.ontogrator.pkg2.VisualNetwork;
import visual.ontogrator.pkg2.VisualNetwork;

/**
 *
 * @author Gabriel
 */
public class Visual extends javax.swing.JFrame {
    ArrayList<Gene> agene = new ArrayList<>();
    DataBaseFilter bancos = new DataBaseFilter();
    ItensFilters itens = new ItensFilters();
    LCSFilter filter = new LCSFilter();
    Lista listagenes = new Lista();
    ListaRede listrede = new ListaRede();
    Network rede;
    VisualNetwork redevisual;
   
    
    public ArrayList<Gene> getAgene() {
        return agene;
    }

    public void setAgene(ArrayList<Gene> agene) {
        this.agene = agene;
    }
    int ngene=0;
    /** Creates new form Visual */
    public Visual() {
        initComponents();
        ButtonGroup bgroup = new ButtonGroup();
        bgroup.add(rbtnGeneID);
        bgroup.add(rbtnLocusTAG);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        pnlPrograma = new javax.swing.JPanel();
        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel5 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        pnlVisualNetwork = new javax.swing.JPanel();
        pnlStatus = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jToolBar1 = new javax.swing.JToolBar();
        jPanel10 = new javax.swing.JPanel();
        btnPesquisar = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        jPanel9 = new javax.swing.JPanel();
        chkPosition = new javax.swing.JCheckBox();
        btnGerarRede = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        jPanel6 = new javax.swing.JPanel();
        rbtnGeneID = new javax.swing.JRadioButton();
        rbtnLocusTAG = new javax.swing.JRadioButton();
        jSeparator4 = new javax.swing.JToolBar.Separator();
        jPanel7 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jPanel8 = new javax.swing.JPanel();
        btnVoltar = new javax.swing.JButton();
        btnAvancar = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jSeparator5 = new javax.swing.JToolBar.Separator();
        pnlProgress = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jProgressBar1 = new javax.swing.JProgressBar();
        jMenuBar1 = new javax.swing.JMenuBar();
        btnOpenList = new javax.swing.JMenu();
        jMenuItem8 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        btnOpenNet = new javax.swing.JMenuItem();
        btnSave = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        jLabel1.setText("jLabel1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Visual Ontogrator 2.0");
        setMinimumSize(new java.awt.Dimension(600, 300));
        getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.Y_AXIS));

        pnlPrograma.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        pnlPrograma.setLayout(new javax.swing.BoxLayout(pnlPrograma, javax.swing.BoxLayout.LINE_AXIS));

        jPanel3.setLayout(new javax.swing.BoxLayout(jPanel3, javax.swing.BoxLayout.Y_AXIS));

        jPanel5.setLayout(new javax.swing.BoxLayout(jPanel5, javax.swing.BoxLayout.Y_AXIS));

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Gene Info"));
        jPanel4.setMaximumSize(new java.awt.Dimension(3000, 3000));
        jPanel4.setMinimumSize(new java.awt.Dimension(10, 10));
        jPanel4.setPreferredSize(new java.awt.Dimension(500, 400));
        jPanel4.setRequestFocusEnabled(false);
        jPanel4.setLayout(new java.awt.GridBagLayout());
        jPanel5.add(jPanel4);

        jScrollPane1.setViewportView(jPanel5);

        jPanel3.add(jScrollPane1);

        jSplitPane1.setRightComponent(jPanel3);

        pnlVisualNetwork.setBorder(javax.swing.BorderFactory.createTitledBorder("Visual Network"));
        pnlVisualNetwork.setMinimumSize(new java.awt.Dimension(100, 100));
        pnlVisualNetwork.setPreferredSize(new java.awt.Dimension(400, 400));
        pnlVisualNetwork.setLayout(new java.awt.CardLayout());
        jSplitPane1.setLeftComponent(pnlVisualNetwork);

        pnlPrograma.add(jSplitPane1);

        getContentPane().add(pnlPrograma);

        pnlStatus.setLayout(new javax.swing.BoxLayout(pnlStatus, javax.swing.BoxLayout.LINE_AXIS));

        jScrollPane2.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
        jScrollPane2.setMinimumSize(new java.awt.Dimension(6, 130));
        jScrollPane2.setPreferredSize(new java.awt.Dimension(100, 130));

        jToolBar1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setMinimumSize(new java.awt.Dimension(800, 130));
        jToolBar1.setPreferredSize(new java.awt.Dimension(800, 130));

        jPanel10.setLayout(new java.awt.GridBagLayout());

        btnPesquisar.setText("Pesquisar");
        btnPesquisar.setFocusable(false);
        btnPesquisar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnPesquisar.setPreferredSize(new java.awt.Dimension(100, 25));
        btnPesquisar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnPesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPesquisarActionPerformed(evt);
            }
        });
        jPanel10.add(btnPesquisar, new java.awt.GridBagConstraints());

        jToolBar1.add(jPanel10);
        jToolBar1.add(jSeparator2);

        jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder("Gerenciar Rede"));
        jPanel9.setLayout(new javax.swing.BoxLayout(jPanel9, javax.swing.BoxLayout.LINE_AXIS));

        chkPosition.setText("Manter Posições");
        chkPosition.setFocusable(false);
        chkPosition.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        chkPosition.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jPanel9.add(chkPosition);

        btnGerarRede.setText("Gerar Rede");
        btnGerarRede.setFocusable(false);
        btnGerarRede.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnGerarRede.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnGerarRede.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGerarRedeActionPerformed(evt);
            }
        });
        jPanel9.add(btnGerarRede);

        jButton5.setText("Gerar Tabela");
        jButton5.setActionCommand("");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        jPanel9.add(jButton5);

        jToolBar1.add(jPanel9);
        jToolBar1.add(jSeparator3);

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Tipo de lista"));
        jPanel6.setPreferredSize(new java.awt.Dimension(120, 86));
        jPanel6.setLayout(new java.awt.GridBagLayout());

        rbtnGeneID.setText("GENE ID");
        rbtnGeneID.setToolTipText("");
        rbtnGeneID.setFocusable(false);
        rbtnGeneID.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        rbtnGeneID.setMinimumSize(new java.awt.Dimension(100, 39));
        rbtnGeneID.setPreferredSize(new java.awt.Dimension(100, 39));
        rbtnGeneID.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbtnGeneIDActionPerformed(evt);
            }
        });
        jPanel6.add(rbtnGeneID, new java.awt.GridBagConstraints());

        rbtnLocusTAG.setSelected(true);
        rbtnLocusTAG.setText("Locus TAG");
        rbtnLocusTAG.setFocusable(false);
        rbtnLocusTAG.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        rbtnLocusTAG.setMinimumSize(new java.awt.Dimension(100, 23));
        rbtnLocusTAG.setPreferredSize(new java.awt.Dimension(100, 23));
        rbtnLocusTAG.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbtnLocusTAGActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        jPanel6.add(rbtnLocusTAG, gridBagConstraints);

        jToolBar1.add(jPanel6);
        jToolBar1.add(jSeparator4);

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("Info Genes"));
        jPanel7.setLayout(new java.awt.GridBagLayout());

        jLabel3.setText("Gene");
        jPanel7.add(jLabel3, new java.awt.GridBagConstraints());

        jPanel8.setLayout(new javax.swing.BoxLayout(jPanel8, javax.swing.BoxLayout.LINE_AXIS));

        btnVoltar.setText("<<");
        btnVoltar.setToolTipText("");
        btnVoltar.setActionCommand("");
        btnVoltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVoltarActionPerformed(evt);
            }
        });
        jPanel8.add(btnVoltar);

        btnAvancar.setText(">>");
        btnAvancar.setToolTipText("");
        btnAvancar.setActionCommand("");
        btnAvancar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAvancarActionPerformed(evt);
            }
        });
        jPanel8.add(btnAvancar);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        jPanel7.add(jPanel8, gridBagConstraints);

        jPanel2.setPreferredSize(new java.awt.Dimension(20, 20));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        jPanel7.add(jPanel2, new java.awt.GridBagConstraints());

        jToolBar1.add(jPanel7);
        jToolBar1.add(jSeparator5);

        pnlProgress.setBorder(javax.swing.BorderFactory.createTitledBorder("Status"));
        pnlProgress.setLayout(new java.awt.GridBagLayout());

        jLabel2.setText("Status");
        jLabel2.setToolTipText("");
        pnlProgress.add(jLabel2, new java.awt.GridBagConstraints());

        jProgressBar1.setMinimumSize(new java.awt.Dimension(50, 14));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        pnlProgress.add(jProgressBar1, gridBagConstraints);

        jToolBar1.add(pnlProgress);

        jScrollPane2.setViewportView(jToolBar1);

        pnlStatus.add(jScrollPane2);

        getContentPane().add(pnlStatus);

        btnOpenList.setText("File");
        btnOpenList.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOpenListActionPerformed(evt);
            }
        });

        jMenuItem8.setText("New");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        btnOpenList.add(jMenuItem8);

        jMenuItem4.setText("Open List");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        btnOpenList.add(jMenuItem4);

        btnOpenNet.setText("Open Network");
        btnOpenNet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOpenNetActionPerformed(evt);
            }
        });
        btnOpenList.add(btnOpenNet);

        btnSave.setText("Save Network");
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });
        btnOpenList.add(btnSave);

        jMenuItem5.setText("Exit");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        btnOpenList.add(jMenuItem5);

        jMenuBar1.add(btnOpenList);

        jMenu2.setText("Select");
        jMenu2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu2ActionPerformed(evt);
            }
        });

        jMenuItem1.setText("Data Base");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem1);

        jMenuItem2.setText("Filters");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem2);

        jMenuItem3.setText("Itens");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem3);

        jMenuItem6.setText("List");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem6);

        jMenuItem7.setText("Network");
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem7);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private  javax.swing.JPanel printInfo(String titulo,String info,int cor){
        Dimension dlabel = new Dimension(150,100);
        Dimension dtext = new Dimension(250,100);
        //painel onde ficarao os componentes
        javax.swing.JPanel jPanel = new javax.swing.JPanel();
        jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.X_AXIS));
       

        //jlabel do titulo
        javax.swing.JLabel jLabel1 = new javax.swing.JLabel(titulo);
        
        
        jLabel1.setPreferredSize(dlabel);

        //jtextarea da info
        javax.swing.JTextPane jTextArea1 = new javax.swing.JTextPane();
        jTextArea1.setPreferredSize(dtext);
        
        jTextArea1.setEditable(false);
        
        jTextArea1.setFont(new java.awt.Font("Arial", 0, 12));

        jTextArea1.setText(info);
      
      if (cor == 1) {
            jPanel.setBackground(new java.awt.Color(153, 204, 255));
         
            jTextArea1.setBackground(new java.awt.Color(254, 250, 226, 100));
            jTextArea1.revalidate();
            jTextArea1.repaint();
        } else {
            jPanel.setBackground(new java.awt.Color(153, 255, 204));
           
            jTextArea1.setBackground(Color.WHITE);
            jTextArea1.revalidate();
            jTextArea1.repaint();
        }

       //adicionar barra de rolagem ao jtexarea
       javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane();
       jScrollPane1.add(jTextArea1);
       jScrollPane1.setBorder(null);
       jScrollPane1.setViewportView(jTextArea1);
       
       //jScrollPane1.revalidate();
       
       jPanel.add(jLabel1);
       jPanel.add(jScrollPane1);

      return jPanel;
        
        
    }
    
    private void imprimir(Gene gene,javax.swing.JPanel panel){
        ArrayList<List<String>> array = gene.getArrayInfo();
        String esp = "\n";
        String info = "";
      
        int flag = 0;
        for(int i=0;i<array.size();i++){
            if (!array.get(i).isEmpty()) {
                for (int j = 0; j < array.get(i).size(); j++) {
                    info = array.get(i).get(j) + esp + info;
                }
               
                panel.add(printInfo(gene.getArrayTitulo().get(i), info, flag));
                panel.setLayout(new java.awt.GridLayout(i+1, 1, 5, 5));
                Dimension panelD = new Dimension(500,i*100); 
                panel.setPreferredSize(panelD);
                
                if (flag == 0) {
                    flag = 1;
                } else {
                    flag = 0;
                }
            }
            info = "";
         }
        
        panel.revalidate();
        panel.repaint();
    }
    
   
private void pesquisa(){
        
        final ArrayList<Gene> agenepesquisa = new ArrayList<>();
       
        Thread threadPesquisa = new Thread () {
        @Override
        public void run () {
            int i = 0;
            String str[] = new String[listagenes.getListPesquisa().size()];
            for(int j=0; j<listagenes.getListPesquisa().size();j++){
                str[j] = listagenes.getListPesquisa().get(j)+"";
            }
            
            SearchEngine bot = new SearchEngine();
            jProgressBar1.setMaximum((str.length) * 4);
            jProgressBar1.setMinimum(0);
            
            //limpar lista antiga se houver uma
            agenepesquisa.clear();
            
            for (String nlista : str) {

                Gene gene = new Gene();
                gene.setNome_Lista(nlista);
                agenepesquisa.add(gene);
                 
                if (bancos.getBancoIndex(0)) {
                    try {
                        jProgressBar1.setValue(i++);
                        jLabel2.setText("Pesquisando " + nlista + " no TAIR");
                        System.out.println(">>>>>>tair<<<<");
                        bot.tair(nlista, gene);
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                }

                if (bancos.getBancoIndex(1)) {
                    try {
                        jProgressBar1.setValue(i++);
                        jLabel2.setText("Pesquisando " + nlista + " no KEGG");
                        System.out.println(">>>>>>kegg<<<<");
                        bot.kegg(nlista, gene);
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                }

                if (bancos.getBancoIndex(2)) {
                    try {
                        jProgressBar1.setValue(i++);
                        jLabel2.setText("Pesquisando " + nlista + " no NCBI");
                        System.out.println(">>>>>>ncbi<<<<");
                        if (rbtnGeneID.isSelected()) {
                            bot.ncbi(nlista, gene);
                        } else {
                            if (gene.getOther_DBs().size() > 3) {
                                bot.ncbi(gene.getGeneid(), gene);
                            }
                        }
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                }

                if (bancos.getBancoIndex(3)) {
                    try {
                        jProgressBar1.setValue(i++);
                        jLabel2.setText("Pesquisando " + nlista + " no YEAST");
                        System.out.println(">>>>>>yeast<<<<");
                        bot.yeast(nlista, gene);
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                }

            }
            jProgressBar1.setValue(0);
            jLabel2.setText("Status");
            listagenes.copytoAgenerede(agenepesquisa);

        }
    ;

    }; 
      
    threadPesquisa.start();
      
        
    }
    
private void btnPesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPesquisarActionPerformed
        
      pesquisa();
        
}//GEN-LAST:event_btnPesquisarActionPerformed

private void btnAvancarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAvancarActionPerformed
    ngene++;
    if (ngene > agene.size() - 1) {
        ngene = agene.size() - 1;
    }
    jPanel4.removeAll();
    try {
        imprimir(agene.get(ngene), jPanel4);
        jLabel3.setText(agene.get(ngene).getNome_Lista() + "");
    } catch (Exception e) {
    };
    jPanel4.revalidate();// TODO add your handling code here:
    jPanel4.repaint();

}//GEN-LAST:event_btnAvancarActionPerformed

private void btnVoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVoltarActionPerformed
 
    ngene--;
    if (ngene < 0) {
        ngene = 0;
    }
    jPanel4.removeAll();
    try {
        imprimir(agene.get(ngene), jPanel4);
        jLabel3.setText(agene.get(ngene).getNome_Lista()+"");
    } catch (Exception e) {
    };
    
    jPanel4.revalidate();// TODO add your handling code here:
    
  
}//GEN-LAST:event_btnVoltarActionPerformed


private void VisualNetwork(){
    agene = listrede.getAgeneselecionado();
    //posicionar os genes na mesma posição que a rede passada
    if (chkPosition.isSelected()) {
        try {
            redevisual.setXY(agene);
        } catch (Exception e) {
        }
    }
    rede = new Network();
   
    rede.filtrar(agene, filter.getVcorte(), filter.getVerif());
    
    //rede.imprimirGlobal();
   // rede.imprimirIndex();
   // rede.imprimirArestas();
    
    redevisual = new VisualNetwork(agene, rede.getNo(),itens.getSelected(),itens.getPalette());
    //enviar itens selecionados para a rede
   
 
    
    pnlVisualNetwork.removeAll();
    pnlVisualNetwork.add(redevisual);
    pnlVisualNetwork.revalidate();
    pnlVisualNetwork.repaint();
}
private void btnGerarRedeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGerarRedeActionPerformed
   VisualNetwork();
    
}//GEN-LAST:event_btnGerarRedeActionPerformed

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
     bancos.setVisible(true);

}//GEN-LAST:event_jMenuItem1ActionPerformed

private void jMenu2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu2ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jMenu2ActionPerformed

private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
    itens.setAgene(agene);
    itens.setVisible(true);
    
}//GEN-LAST:event_jMenuItem3ActionPerformed

private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
    filter.setAgene(agene);
    filter.setVisible(true);
    
        
}//GEN-LAST:event_jMenuItem2ActionPerformed

private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
  System.exit(0);
}//GEN-LAST:event_jMenuItem5ActionPerformed

private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
  
    File file = IOFile.OpenListFile();
    ArrayList<String> lista = new ArrayList<>();
    
    try {
       lista = IOFile.ReadFile(file);
    } catch (Exception e) {
        System.out.println("Erro ao carregar arquivo");
    }
        String aux="";
        for (int i = 0; i < lista.size(); i++) {
            aux = aux+lista.get(i)+"\n";
        }
        listagenes.setTxtlista(aux);
        //listagenes.transfereLista();
      
   
}//GEN-LAST:event_jMenuItem4ActionPerformed

private void btnOpenListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOpenListActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_btnOpenListActionPerformed

private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
    LoadSave save = new LoadSave();
    
    JFileChooser fc = new JFileChooser();
    fc.showDialog(null, null);
    String arquivo = fc.getSelectedFile().getAbsolutePath();
    
    try{
    redevisual.setXY(agene);
    }catch(Exception e){
        System.out.println(e);
    }
    
    save.setAgene(agene);
    
    save.setValores(filter.getValores());
    
    save.setSelecionados(itens.getApintar());
    
    save.setRede(rede);
    
    save.setList(listagenes.getTxtlista());
    save.setListModel(listagenes.getListModel());
    save.setListPesquisa(listagenes.getListPesquisa());
    save.setAgenerede(listagenes.getAgenerede());
     

    save.setAgeneselecionado(listrede.getAgeneselecionado());
 

    
    
    try {
        FileOutputStream fileOut =
                new FileOutputStream(arquivo);
        ObjectOutputStream out =
                new ObjectOutputStream(fileOut);
        out.writeObject(save);
        out.close();
        fileOut.close();
    } catch (IOException i) {
        i.printStackTrace();
    }
    
}//GEN-LAST:event_btnSaveActionPerformed

private void load(LoadSave load){
     agene = load.getAgene();
     
     
 
    try {
         //atualizar filtros
        filter.setAgene(agene);
        filter.atualizar();
        filter.setValores(load.getValores());
        filter.salvar();
    } catch (Exception e) {
        System.out.println("Erro ao atualizar filtro, ou criação de nova rede");
        System.out.println(e);
    }



    try {
        //atualizar itens
        itens.setAgene(agene);
        itens.atualizar();
        itens.setApintar(load.getSelecionados());
        itens.salvar();
    } catch (Exception e) {
        System.out.println("Erro ao atualizar intens, ou criação de nova rede");
        System.out.println(e);
    }

      
      
      //carregar rede
      rede = load.getRede();
      //VisualNetwork();
      
    //carregar lista genes
    try {
        listagenes.setTxtlista(load.getList());
        listagenes.setListModel(load.getListModel());
        listagenes.setListPesquisa(load.getListPesquisa());
        listagenes.setAgenerede(load.getAgenerede());
    } catch (Exception e) {
        System.out.println("Erro ao atualizar lista genes, ou criação de nova rede");
        System.out.println(e);
    }

    try {
        listrede.setAgenerede(load.getAgenerede());
        listrede.setAgeneselecionado(load.getAgeneselecionado());
    } catch (Exception e) {
        System.out.println("Erro ao atualizar lista rede, ou criação de nova rede");
        System.out.println(e);
    }
      
      //limpar panel info
      jPanel4.removeAll();
}
private void btnOpenNetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOpenNetActionPerformed
    LoadSave load;
    
    JFileChooser fc = new JFileChooser();
    fc.showDialog(null, null);
    String arquivo = fc.getSelectedFile().getAbsolutePath();
      try
      {
         FileInputStream fileIn =
                          new FileInputStream(arquivo);
         ObjectInputStream in = new ObjectInputStream(fileIn);
         load = (LoadSave) in.readObject();
         in.close();
         fileIn.close();
      }catch(IOException i)
      {
         i.printStackTrace();
         return;
      }catch(ClassNotFoundException c)
      {
         c.printStackTrace();
         return;
      }
      
     load(load);
      
    
}//GEN-LAST:event_btnOpenNetActionPerformed


private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
Tabela tabela = new Tabela(agene);
tabela.setVisible(true);
}//GEN-LAST:event_jButton5ActionPerformed

private void rbtnLocusTAGActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbtnLocusTAGActionPerformed

}//GEN-LAST:event_rbtnLocusTAGActionPerformed

private void rbtnGeneIDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbtnGeneIDActionPerformed

}//GEN-LAST:event_rbtnGeneIDActionPerformed

private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
listagenes.setVisible(true);
}//GEN-LAST:event_jMenuItem6ActionPerformed

private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
    listrede.setAgenerede(listagenes.getAgenerede());
    listrede.setVisible(true);
}//GEN-LAST:event_jMenuItem7ActionPerformed

private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
    LoadSave novarede = new LoadSave();
    agene = new ArrayList<>();
    bancos = new DataBaseFilter();
    itens = new ItensFilters();
    filter = new LCSFilter();
    listagenes = new Lista();
    listrede = new ListaRede();
    jLabel3.setText("Gene");
    
    pnlVisualNetwork.removeAll();
    pnlVisualNetwork.repaint();
    
    jPanel4.removeAll();
    jPanel4.repaint();
    load(novarede);
}//GEN-LAST:event_jMenuItem8ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Visual.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Visual.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Visual.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Visual.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Visual().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAvancar;
    private javax.swing.JButton btnGerarRede;
    private javax.swing.JMenu btnOpenList;
    private javax.swing.JMenuItem btnOpenNet;
    private javax.swing.JButton btnPesquisar;
    private javax.swing.JMenuItem btnSave;
    private javax.swing.JButton btnVoltar;
    private javax.swing.JCheckBox chkPosition;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JToolBar.Separator jSeparator4;
    private javax.swing.JToolBar.Separator jSeparator5;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JPanel pnlPrograma;
    private javax.swing.JPanel pnlProgress;
    private javax.swing.JPanel pnlStatus;
    private javax.swing.JPanel pnlVisualNetwork;
    private javax.swing.JRadioButton rbtnGeneID;
    private javax.swing.JRadioButton rbtnLocusTAG;
    // End of variables declaration//GEN-END:variables
}
